@@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base |
||
| 12 | 12 |
before_filter :configure_permitted_parameters, if: :devise_controller? |
| 13 | 13 |
|
| 14 | 14 |
def configure_permitted_parameters |
| 15 |
- devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:first_name, :last_name, :email, :current_password, :avatar, :password, :password_confirmation) }
|
|
| 15 |
+ devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:first_name, :last_name, :email, :current_password, :avatar, :password, :password_confirmation, :avatar_tmp, :avatar_processing) }
|
|
| 16 | 16 |
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :email, :password) }
|
| 17 | 17 |
end |
| 18 | 18 |
|
@@ -75,7 +75,7 @@ class BlogPostsController < ApplicationController |
||
| 75 | 75 |
|
| 76 | 76 |
# Never trust parameters from the scary internet, only allow the white list through. |
| 77 | 77 |
def blog_post_params |
| 78 |
- params.require(:blog_post).permit(:title, :slug, :content, :published, :description, :image) |
|
| 78 |
+ params.require(:blog_post).permit(:title, :slug, :content, :published, :description, :image, :image_tmp, :image_processing) |
|
| 79 | 79 |
end |
| 80 | 80 |
|
| 81 | 81 |
def authenticate_user |
@@ -4,4 +4,6 @@ class BlogPost < ActiveRecord::Base |
||
| 4 | 4 |
validates_presence_of :title, :slug |
| 5 | 5 |
belongs_to :author, :class_name => "User" |
| 6 | 6 |
mount_uploader :image, CoverUploader |
| 7 |
+ process_in_background :image |
|
| 8 |
+ store_in_background :image |
|
| 7 | 9 |
end |
@@ -10,6 +10,8 @@ class User < ActiveRecord::Base |
||
| 10 | 10 |
has_many :posts |
| 11 | 11 |
|
| 12 | 12 |
mount_uploader :avatar, AvatarUploader |
| 13 |
+ process_in_background :avatar |
|
| 14 |
+ store_in_background :avatar |
|
| 13 | 15 |
|
| 14 | 16 |
def full_name |
| 15 | 17 |
name = self.first_name.to_s + ' ' + self.last_name.to_s |
@@ -6,6 +6,8 @@ class AvatarUploader < CarrierWave::Uploader::Base |
||
| 6 | 6 |
# include CarrierWave::RMagick |
| 7 | 7 |
include CarrierWave::MiniMagick |
| 8 | 8 |
include CarrierWave::MimeTypes |
| 9 |
+ |
|
| 10 |
+ include ::CarrierWave::Backgrounder::Delay |
|
| 9 | 11 |
|
| 10 | 12 |
# Choose what kind of storage to use for this uploader: |
| 11 | 13 |
|
@@ -32,8 +34,12 @@ class AvatarUploader < CarrierWave::Uploader::Base |
||
| 32 | 34 |
"uploads/#{mounted_as}/#{model.id}"
|
| 33 | 35 |
end |
| 34 | 36 |
|
| 37 |
+ def root |
|
| 38 |
+ "#{Rails.root}/public"
|
|
| 39 |
+ end |
|
| 40 |
+ |
|
| 35 | 41 |
def cache_dir |
| 36 |
- " ./tmp/uploads/#{mounted_as}/#{model.id}"
|
|
| 42 |
+ " ./tmp/uploads/#{mounted_as}/"
|
|
| 37 | 43 |
end |
| 38 | 44 |
|
| 39 | 45 |
# Provide a default URL as a default if there hasn't been a file uploaded: |
@@ -6,6 +6,8 @@ class CoverUploader < CarrierWave::Uploader::Base |
||
| 6 | 6 |
# include CarrierWave::RMagick |
| 7 | 7 |
include CarrierWave::MiniMagick |
| 8 | 8 |
include CarrierWave::MimeTypes |
| 9 |
+ |
|
| 10 |
+ include ::CarrierWave::Backgrounder::Delay |
|
| 9 | 11 |
|
| 10 | 12 |
# Choose what kind of storage to use for this uploader: |
| 11 | 13 |
|
@@ -32,8 +34,12 @@ class CoverUploader < CarrierWave::Uploader::Base |
||
| 32 | 34 |
"uploads/#{mounted_as}/#{model.id}"
|
| 33 | 35 |
end |
| 34 | 36 |
|
| 37 |
+ def root |
|
| 38 |
+ "#{Rails.root}/public"
|
|
| 39 |
+ end |
|
| 40 |
+ |
|
| 35 | 41 |
def cache_dir |
| 36 |
- " ./tmp/uploads/#{mounted_as}/#{model.id}"
|
|
| 42 |
+ " ./tmp/uploads/#{mounted_as}/"
|
|
| 37 | 43 |
end |
| 38 | 44 |
|
| 39 | 45 |
# Provide a default URL as a default if there hasn't been a file uploaded: |
@@ -0,0 +1,8 @@ |
||
| 1 |
+class AddProcessingToAvatarAndConverImages < ActiveRecord::Migration |
|
| 2 |
+ def change |
|
| 3 |
+ add_column :users, :avatar_tmp, :string |
|
| 4 |
+ add_column :users, :avatar_processing, :boolean, null: false, default: false |
|
| 5 |
+ add_column :blog_posts, :image_tmp, :string |
|
| 6 |
+ add_column :blog_posts, :image_processing, :boolean, null: false, default: false |
|
| 7 |
+ end |
|
| 8 |
+end |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 |
# |
| 12 | 12 |
# It's strongly recommended that you check this file into your version control system. |
| 13 | 13 |
|
| 14 |
-ActiveRecord::Schema.define(version: 20150109224815) do |
|
| 14 |
+ActiveRecord::Schema.define(version: 20150110020743) do |
|
| 15 | 15 |
|
| 16 | 16 |
# These are extensions that must be enabled in order to support this database |
| 17 | 17 |
enable_extension "plpgsql" |
@@ -26,6 +26,8 @@ ActiveRecord::Schema.define(version: 20150109224815) do |
||
| 26 | 26 |
t.datetime "updated_at" |
| 27 | 27 |
t.string "description" |
| 28 | 28 |
t.string "image" |
| 29 |
+ t.string "image_tmp" |
|
| 30 |
+ t.boolean "image_processing", default: false, null: false |
|
| 29 | 31 |
end |
| 30 | 32 |
|
| 31 | 33 |
add_index "blog_posts", ["author_id"], name: "index_blog_posts_on_author_id", using: :btree |
@@ -90,12 +92,12 @@ ActiveRecord::Schema.define(version: 20150109224815) do |
||
| 90 | 92 |
end |
| 91 | 93 |
|
| 92 | 94 |
create_table "users", force: true do |t| |
| 93 |
- t.string "email", default: "", null: false |
|
| 94 |
- t.string "encrypted_password", default: "", null: false |
|
| 95 |
+ t.string "email", default: "", null: false |
|
| 96 |
+ t.string "encrypted_password", default: "", null: false |
|
| 95 | 97 |
t.string "reset_password_token" |
| 96 | 98 |
t.datetime "reset_password_sent_at" |
| 97 | 99 |
t.datetime "remember_created_at" |
| 98 |
- t.integer "sign_in_count", default: 0, null: false |
|
| 100 |
+ t.integer "sign_in_count", default: 0, null: false |
|
| 99 | 101 |
t.datetime "current_sign_in_at" |
| 100 | 102 |
t.datetime "last_sign_in_at" |
| 101 | 103 |
t.string "current_sign_in_ip" |
@@ -106,6 +108,8 @@ ActiveRecord::Schema.define(version: 20150109224815) do |
||
| 106 | 108 |
t.datetime "updated_at" |
| 107 | 109 |
t.boolean "admin" |
| 108 | 110 |
t.string "avatar" |
| 111 |
+ t.string "avatar_tmp" |
|
| 112 |
+ t.boolean "avatar_processing", default: false, null: false |
|
| 109 | 113 |
end |
| 110 | 114 |
|
| 111 | 115 |
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree |